package com.jie.jie.mvp.model;

import com.jie.jie.mvp.contract.Meicontract;
import com.jie.jie.mvp.util.DataUtil;
import com.jie.jie.mvp.util.GankService;
import com.jie.jie.mvp.util.RetrofitManager1;
import com.jie.jie.mvp.util.RetrofitManager2;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by jie on 2017/1/23.
 */

public class MeiModel implements Meicontract.Model{
    public Observable<List<MeiziBean>> getMeizi(final int page) {
        return RetrofitManager1
                .getInstance()
                .createService(GankService.class)
                .getMeizi(page)
                .map(new Func1<String, List<MeiziBean>>() {
                    @Override
                    public List<MeiziBean> call(String s) {
                        return DataUtil.getMMHomeImgUrl(s);
                    }
                })
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());
//                .observeOn(Schedulers.)
    }

    public Observable<List<MeiziBean>> getmizi(final int page, final String url) {
       return RetrofitManager2.getInstance(url)
               .createService(GankService.class)
               .getMeizi(page)
               .map(new Func1<String, List<MeiziBean>>() {
                   @Override
                   public List<MeiziBean> call(String s) {
                       ArrayList<MeiziBean> mmHomeImgUrl = DataUtil.getMMLabelImgUrl(s);
                       return mmHomeImgUrl;
                   }
               })
               .subscribeOn(Schedulers.newThread())
               .observeOn(AndroidSchedulers.mainThread());

    }


}
